#include <algorithm>
#include <cstdint>
#include <iostream>
#include <istream>
#include <vector>
using ll = int64_t;

const ll inf=1e9;

int main(){
    std::iostream::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

    ll n;
    std::cin>>n;
    std::vector<std::vector<ll>> dpmax(2*n+1,std::vector<ll>(2*n+1,-inf)),
                                    dpmin(2*n+1,std::vector<ll>(2*n+1,inf)),
                                    cost(2*n+1,std::vector<ll>(2*n+1));

    for(ll i=1;i<=n;i++){
        std::cin>>cost[i][i];
        cost[n+i][n+i]=cost[i][i];
        dpmin[i][i]=dpmax[i][i]=0;
        dpmin[n+i][n+i]=dpmax[n+i][n+i]=0;
    }

    for(ll len=2;len<=n;++len){
        for(ll i=1;i<=2*n-len;i++){
            ll j=i+len-1;
            for(ll k=i;k<j;k++){
                cost[i][j]=cost[i][k]+cost[k+1][j];
            }
        }
    }

    for(ll len=2;len<=n;len++){
        for(ll i=1;i<=2*n-len;i++){
            ll j=i+len-1;
            for(ll k=i;k<j;k++){
                dpmax[i][j]=std::max(dpmax[i][j],dpmax[i][k]+dpmax[k+1][j]+cost[i][j]);
                dpmin[i][j]=std::min(dpmin[i][j],dpmin[i][k]+dpmin[k+1][j]+cost[i][j]);
            }
        }
    }

    ll minans=inf,maxans=-inf;
    for(ll i=1;i<=n;i++){
        minans=std::min(minans,dpmin[i][i+n-1]);
        maxans=std::max(maxans,dpmax[i][i+n-1]);
    }

    std::cout<<minans<<"\n"<<maxans<<"\n";
}   